home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / PRGMANIA / BFED.10 / ONEPAGE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-23  |  7.1 KB  |  324 lines

  1. /********************************************
  2.     file: onepage.c
  3.     utility: Display one window full of data.
  4.     date: 1989
  5.     author: Jim Charlton
  6.     modifications:
  7.         1995: C. Moreau:
  8.     comments:
  9. *********************************************/
  10.  
  11. /********************************************
  12.     includes
  13. *********************************************/
  14. #include <stdio.h>
  15. #include <string.h>
  16.  
  17. #ifdef __PUREC__ 
  18. #include <aes.h>
  19. #include <vdi.h>
  20. #include <compend.h>
  21. #else
  22. #include <aesbind.h>
  23. #include <vdibind.h>
  24. #endif
  25.  
  26. #include "cursor.h"
  27. #include "init.h"
  28. #include "onepage.h"
  29. #include "wind.h"
  30.  
  31. /********************************************
  32.     defines
  33. *********************************************/
  34.  
  35. /********************************************
  36.     locals vars declarations & definitions
  37. *********************************************/
  38.  
  39. /********************************************
  40.     globals vars declarations
  41. *********************************************/
  42. char hexa_str[80], ascii_str[80];
  43. char table[600];
  44.  
  45. /********************************************
  46.     locals functions declarations
  47. *********************************************/
  48. static void one_line0(windowptr    thewin,long pos);
  49. static void one_line1(windowptr    thewin,long pos);
  50.  
  51. /********************************************
  52.     globals functions definitions
  53. *********************************************/
  54. /*
  55.     name: one_page
  56.     utility: draw one window full of data
  57.     comment: 
  58.     parameters:
  59.     return:
  60.     date: 1989
  61.     author: Jim Charlton
  62.     modifications:
  63.         1995: C. Moreau: 
  64. */
  65. void one_page(windowptr thewin, GRECT *r1)
  66. {
  67.         /* number of char in the window */
  68.     long nc = (thewin->work.g_h/gl_hchar)*NB_DATA_IN_LINE;
  69.     register long pos_char;
  70.  
  71.         /* Clipping on */
  72.     pxyarray[0] = r1->g_x;
  73.     pxyarray[1] = r1->g_y;
  74.     pxyarray[2] = r1->g_x + r1->g_w-1;
  75.     pxyarray[3] = r1->g_y + r1->g_h-1;
  76.     vs_clip(thewin->graf.handle, CLIP_ON, pxyarray);
  77.  
  78.     if (partial)
  79.     {
  80.         nc -= thewin->position - thewin->topchar + NB_DATA_IN_LINE;
  81.  
  82.         for (pos_char = 0; pos_char < nc; pos_char += NB_DATA_IN_LINE)
  83.         {
  84.             one_line0(thewin, thewin->position+pos_char);
  85.         }
  86.  
  87.         partial = FALSE;
  88.     }
  89.     else
  90.     {
  91.         window_blank(thewin);
  92.  
  93.         for (pos_char = 0; pos_char < nc; pos_char += NB_DATA_IN_LINE)
  94.         {
  95.             one_line0(thewin, thewin->topchar+pos_char);
  96.         }
  97.     }
  98.  
  99.     vs_clip(thewin->graf.handle, CLIP_OFF, pxyarray);
  100. }
  101.  
  102. /*
  103.     name: getbyte
  104.     utility: retreive any byte in file in ram
  105.     comment: 
  106.     parameters:
  107.     return:
  108.     date: 1989
  109.     author: Jim Charlton
  110.     modifications:
  111. */
  112. unsigned getbyte(windowptr thewin, long pos)
  113. {    
  114.     if (pos < thewin->flen)
  115.     {
  116.         linkbufptr amem = thewin->headptr;
  117.         char *addr;
  118.         
  119.         while (amem->inuse<=pos)
  120.         {
  121.             pos -= amem->inuse;
  122.             amem = amem->next;
  123.         }
  124.         addr = (char *)(amem->block+pos);
  125.         return (*addr);
  126.     }
  127.     else
  128.         return ((unsigned)0x00);
  129. }
  130.  
  131. /*
  132.     name: putbyte
  133.     utility: put byte lnum into file at pos
  134.     comment: 
  135.     parameters:
  136.     return:
  137.     date: 1989
  138.     author: Jim Charlton
  139.     modifications:
  140. */
  141. void putbyte(windowptr thewin, long pos, long lnum)
  142. {
  143.     if (pos < thewin->flen)
  144.     {
  145.         linkbufptr amem = thewin->headptr;
  146.         char *addr;
  147.         
  148.         while (amem->inuse<=pos)
  149.         {
  150.             pos -= amem->inuse;
  151.             amem = amem->next;
  152.         }
  153.         addr = (char *)(amem->block+pos);
  154.         *addr = (char)lnum;
  155.         thewin->changed = TRUE;
  156.     }
  157. }
  158.  
  159. /*
  160.     name: one_line0
  161.     utility: 
  162.     comment: 
  163.     parameters:
  164.     return:
  165.     date: 1989
  166.     author: Jim Charlton
  167.     modifications:
  168. */
  169. static void one_line0(windowptr thewin, long pos)
  170. {
  171.         /* aligned position of data in file */
  172.     const long aligned_pos = (pos/NB_DATA_IN_LINE)*NB_DATA_IN_LINE;        /* take the 16 multiple closer */
  173.  
  174.     if (     (aligned_pos > thewin->endmark)
  175.             || ( (aligned_pos+NB_DATA_IN_LINE) < thewin->startmark ) )
  176.         one_line1(thewin, aligned_pos);
  177.     else
  178.         one_line2(thewin, aligned_pos);
  179. }
  180.  
  181. /*
  182.     name: one_line1
  183.     utility: handles unmarked text
  184.     comment: 
  185.     parameters:
  186.         windowptr thewin:    window data.
  187.         long pos: aligned position.
  188.     return:
  189.         none
  190.     date: 1989
  191.     author: Jim Charlton
  192.     modifications:
  193.         dec 1996: C. Moreau: Take off rounding to 16 (aligned pos) 
  194. */
  195. static void one_line1(windowptr thewin, long pos)
  196. {
  197.         /* line number in window */
  198.     const int lineno = (int)(pos - thewin->topchar)/NB_DATA_IN_LINE;
  199.     int tx = thewin->work.g_x + 7;
  200.     int ty = thewin->work.g_y + gl_hchar*(lineno+1);
  201.     unsigned num;
  202.     register int wordno;    /* word number on line */
  203.     register int datano;    /* data number in word */
  204.     unsigned char *hexa_ptr = hexa_str;
  205.     unsigned char *ascii_ptr = ascii_str;
  206.  
  207.     for (wordno=0; wordno<NB_DATA_IN_LINE; wordno+=2)
  208.     {
  209.         for (datano=0; datano<2 ; datano++)
  210.         {
  211.             if (pos+wordno+datano < thewin->flen-1)
  212.             {
  213.                 num = getbyte(thewin, pos+wordno+datano);
  214.                 if (num)
  215.                     *(ascii_ptr++) = num;
  216.                 else
  217.                     *(ascii_ptr++) = BLANK;
  218.  
  219.                 memcpy(hexa_ptr, table+num*2, 2);
  220.                 hexa_ptr += 2;
  221.             }
  222.             else
  223.             {
  224.                 *(ascii_ptr++) = BLANK;
  225.  
  226.                 memcpy(hexa_ptr, DOUBLE_BLANK, 2);
  227.                 hexa_ptr += 2;
  228.             }
  229.         }
  230.         memcpy(hexa_ptr, DOUBLE_BLANK, 2);
  231.         hexa_ptr += 2;
  232.     }
  233.     memcpy(hexa_ptr, DOUBLE_BLANK, 3);
  234.     hexa_ptr += 3;
  235.     
  236.     vswr_mode(thewin->graf.handle, MD_REPLACE);
  237.     v_gtext(thewin->graf.handle, tx, ty, hexa_str);
  238.     
  239.     tx += ASCII_DATA_OFFSET*gl_wchar; 
  240.     *(ascii_ptr++) = '\0';
  241.     v_gtext(thewin->graf.handle, tx, ty, ascii_str);
  242. }
  243.  
  244. /*
  245.     name: one_line2
  246.     utility: handles mixed marked and unmarked
  247.     comment: 
  248.         windowptr thewin:    window data.
  249.         long pos: aligned position.
  250.     return:
  251.         none
  252.     date: 1989
  253.     author: Jim Charlton
  254.     modifications:
  255.         dec 1996: C. Moreau: Take off rounding to 16 (aligned pos) 
  256. */
  257. void one_line2(windowptr thewin,long pos)
  258. {
  259.     unsigned num;
  260.     register int wordno;    /* word number on line */
  261.     register int datano;    /* data number in word */
  262.     const int lineno = (int)(pos - thewin->topchar)/NB_DATA_IN_LINE;
  263.     int tx = thewin -> work.g_x + 7;
  264.     int ty = thewin -> work.g_y + gl_hchar*(lineno+1);
  265.     char *ascii_ptr = ascii_str;
  266.  
  267.     hexa_str[2]='\0';    /* prepare string (always 2 char long) */
  268.     
  269.     for (wordno = 0; wordno < NB_DATA_IN_LINE; wordno += 2)
  270.     {
  271.         for (datano = 0; datano < 2; datano++)
  272.         {
  273.             if(pos+wordno+datano < thewin->flen-1)
  274.             {
  275.                 num = getbyte(thewin, pos+wordno+datano);
  276.                 if (num)
  277.                     *(ascii_ptr++) = num;
  278.                 else
  279.                     *(ascii_ptr++) = BLANK;
  280.  
  281.                 strncpy(hexa_str, table+num*2, 2);
  282.  
  283.                 if( (pos+wordno+datano >= thewin->startmark)    \
  284.                         && (pos+wordno+datano <= thewin->endmark) ) 
  285.                     vswr_mode(thewin->graf.handle, MD_ERASE);
  286.             }
  287.             else
  288.             {
  289.                 strncpy(hexa_str, DOUBLE_BLANK, 3);
  290.                 *(ascii_ptr++) = BLANK;
  291.             }
  292.  
  293.             v_gtext(thewin->graf.handle, tx, ty, hexa_str);
  294.             vswr_mode(thewin->graf.handle, MD_REPLACE);
  295.             tx += 2*gl_wchar;
  296.         }
  297.  
  298.         strncpy(hexa_str, DOUBLE_BLANK, 3);
  299.         v_gtext(thewin->graf.handle, tx, ty, hexa_str);
  300.         tx += 2*gl_wchar;
  301.     }
  302.  
  303.     *(ascii_ptr++)='\0';
  304.     v_gtext(thewin->graf.handle, tx, ty, ascii_str);
  305. }
  306.  
  307. /*
  308.     name: set_table
  309.     utility: makes a table of ASCII hex bytes for 0 to 255
  310.     comment: 
  311.     parameters: none
  312.     return: none
  313.     date: 1989
  314.     author: Jim Charlton
  315.     modifications:
  316. */
  317. void set_table(void)
  318. {
  319.     register unsigned i;
  320.     
  321.     for(i=0; i<256; i++)
  322.         sprintf(table+2*i, "%02x", i);
  323. }
  324.